//
//  ViewController.m
//  FuZhu
//
//  Created by app on 2017/9/14.
//  Copyright © 2017年 王文. All rights reserved.
//

#import "ViewController.h"
#import "SDCycleScrollView.h"
#import "RSWebViewViewController.h"
#import "CustomSegmentControl.h"
#import <UShareUI/UShareUI.h>
#import <UMSocialCore/UMSocialCore.h>
#import "YBPopupMenu.h"
#import "BRPickerView.h"

@interface ViewController ()<SDCycleScrollViewDelegate,YBPopupMenuDelegate>
@property (nonatomic, strong) CustomSegmentControl * segmentBar;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"第一页";
    
    NSArray *images = @[@"http://twt.img.iwala.net/upload/118c59e1b27fd575.jpg",
                        @"http://twt.img.iwala.net/upload/357797c67b3f7033.jpg",
                        @"http://twt.img.iwala.net/upload/a9a69883ba624e67.jpg",
                        @"http://twt.img.iwala.net/upload/858913320bff6162.jpg",
                        @"http://twt.img.iwala.net/upload/21359667942b4065.jpg",
                        @"http://twt.img.iwala.net/upload/93f0689ec10d5033.jpg"];
    SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, 375, 200) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
//    cycleScrollView2.titlesGroup = @[@"第一张",@"第二章",@"第三章",@"第四章",@"第五章"];
    cycleScrollView2.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    cycleScrollView2.pageDotColor = [UIColor redColor];
    cycleScrollView2.imageURLStringsGroup = images;
    cycleScrollView2.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
//    cycleScrollView2.scrollDirection = UICollectionViewScrollDirectionVertical;
    [self.view addSubview:cycleScrollView2];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    NSMutableAttributedString *str = [@"wangwen" changeFont:[UIFont systemFontOfSize:22] andRange:NSMakeRange(0, 1)];
    str  =[@"wangwen" changeFont:[UIFont systemFontOfSize:22] andRange:NSMakeRange(4, 1)];
    label.attributedText = str;
    [self.view addSubview:label];
    
    UIImageView *imageIV = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)];
    imageIV.tag = 999;
    [self.view addSubview:imageIV];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPhoto:)];
    imageIV.userInteractionEnabled = YES;
    [imageIV addGestureRecognizer:tap];
    [imageIV sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505390447328&di=fc04b76baf1cbb9673f323819385069f&imgtype=0&src=http%3A%2F%2Fwww.fmscg.com%2Fuploads%2Fv_pic%2F2013-09%2F12%2F20130912231159_44147_7226.jpg"]];
    
//    [HttpRequest getInfo:@"" successBlock:^(id responseObject) {
//        
//    } failedBlock:^(NSError *error) {
//        
//    }];
    
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    shareBtn.frame = CGRectMake(100, 350, 100, 40);
    shareBtn.backgroundColor = [UIColor orangeColor];
    [shareBtn setTitle:@"分享" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [shareBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shareBtn];
    
    [self initSegmentBar];
    
}
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu {
    NSLog(@"菜单按钮点击了");
}
-(void)btnClick:(UIButton *)sender {
    [BRAddressPickerView showAddressPickerWithDefaultSelected:@[@10, @0, @3] isAutoSelect:YES resultBlock:^(NSArray *selectAddressArr) {
        NSLog(@"选择的地址：%@",[NSString stringWithFormat:@"%@%@%@", selectAddressArr[0], selectAddressArr[1], selectAddressArr[2]]);
    }];
}

- (void)initSegmentBar {
    CustomSegmentControl *segmentBar = [[CustomSegmentControl alloc]initWithItems:@[@"联系我们",@"介绍"]];
    self.segmentBar = segmentBar;
    segmentBar.st_size = CGSizeMake(kWidth, 40);
    segmentBar.st_x = 0;
    segmentBar.st_y = 450;
    segmentBar.font = [UIFont boldSystemFontOfSize:16];
    segmentBar.textColor = [UIColor blackColor];
    segmentBar.selectedTextColor = RGBA(16, 142, 233, 1);
    segmentBar.backgroundColor = [UIColor orangeColor];
//        _segmentBar.selectedSegmentIndex = _swipeTableView.currentItemIndex;
    [segmentBar addTarget:self action:@selector(changeSwipeViewIndex:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segmentBar];
}

- (void)changeSwipeViewIndex:(UISegmentedControl *)seg {
    
//    [_swipeTableView scrollToItemAtIndex:seg.selectedSegmentIndex animated:NO];
//    NSLog(@"点击选择的下标：%ld 当前view下标：%ld",seg.selectedSegmentIndex,self.swipeTableView.currentItemIndex);
}
#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", (long)index);
//    NextVC *nextVC = [[NextVC alloc]init];
//    [self.navigationController pushViewController:nextVC animated:YES];
    RSWebViewViewController *rsWebVC = [[RSWebViewViewController alloc]init];
    [self.navigationController pushViewController:rsWebVC animated:YES];
    
}
- (void)tapPhoto:(UITapGestureRecognizer *)recognizer {
    
    MJPhotoBrowser *brower = [[MJPhotoBrowser alloc] init];
    //2.告诉图片浏览器显示所有的图片
    NSMutableArray *photos = [NSMutableArray array];
    NSArray *imageArr = @[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505390447328&di=fc04b76baf1cbb9673f323819385069f&imgtype=0&src=http%3A%2F%2Fwww.fmscg.com%2Fuploads%2Fv_pic%2F2013-09%2F12%2F20130912231159_44147_7226.jpg"];
    for (int i = 0 ; i < imageArr.count; i++) {
        //传递数据给浏览器
        MJPhoto *photo = [[MJPhoto alloc] init];
        photo.url = [NSURL URLWithString:imageArr[i]];
        UIImageView *view = [self.view viewWithTag:999+i];
        photo.srcImageView = view; //设置来源哪一个UIImageView
        [photos addObject:photo];
    }
    brower.photos = photos;
    
    //3.设置默认显示的图片索引
    brower.currentPhotoIndex = recognizer.view.tag - 999;
    
    //4.显示浏览器
    [brower show];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
